/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ted;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author ted.yu
 */
public class ConnDb {
        private static final String driver="com.mysql.jdbc.Driver";
	private static final String url="jdbc:mysql://usa50mysql.mianbeian.info:3306/a0918131352?autoReconnect=true";
	private static final String user="a0918131352";
	private static final String pass="18999507";
	Connection con=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	

	
	public boolean islogin(String username, String password) {
		boolean flag=false;
		try{
			Class.forName(driver);
			con=DriverManager.getConnection(url,user,pass);
//			System.out.println("user:"+username);
//			System.out.println("pass:"+password);
			String sql="select username,password from sscuser where username=? and password=?";
			ps=con.prepareStatement(sql);
			
			ps.setString(1,username);
			ps.setString(2,password);
			
			rs=ps.executeQuery();
			
			if(rs.next()){
				flag= true;
			}
			
		}catch(Exception e ){
			System.out.println("conn mysql fail------------------------------------");
			e.printStackTrace();
		}
		return flag;
	}


        public static void main(String args[]){
            
            ConnDb c = new ConnDb();
            
            System.out.println(c.islogin("test", "test"));
            
        }
    
}
